<?php

$tab = array(
0=>"	zero",
1=>"	un",
2=>"	deux",
3=>"	trois",
4=>"	quatre",
5=>"	cinq",
6=>"	six",
7=>"	sept",
8=>"	huit",
9=>"	neuf",
10=>"	dix",
11=>"	onze",
12=>"	douze",
13=>"	treize",
14=>"	quatorze",
15=>"	quinze",
16=>"	seize",
17=>"  dix-sept",
18=>" 	dix-huit",
19=>"	dix-neuf",
20=>" 	vingt",
21=>" 	vingt et un",
22=>" 	vingt-deux",
23=>"	vingt-trois",
24=>"	vingt-quatre",
25=>"	vingt-cinq",
26=>"	vingt-six",
27=>"	vingt-sept",
28=>"	vingt-huit",
29=>" 	vingt-neuf",
30=>" 	trente");

	$Nart = $_GET["NArticle"];
	$article = GetArticle($Nart);
	
	if(isset($_POST['envoyer']))
	{
		$nom = htmlentities($_POST['nom']);
		$mail = $_POST['mail'];
		$texte =  htmlspecialchars($_POST['texte']);
		$bot = $_POST['terminator-killer'];
		$reponse = $_SESSION['reponse'];
		
		if($_POST['nom'] != "" AND $_POST['texte'] != ""){
			if($bot == $reponse)
				NewCom($nom, $mail, $texte, $Nart);
			else
				echo "<p class='erreur'>Va t'en enfoir&eacute; de bot communiste !!!!</p>";
		}
		else{
			echo "<p class='erreur'>Vous n'avez pas rempli tous les champs </p>";
		}
	}	
	
	$nbcom = NbCom($Nart);
	
	if( isset($_GET["NPage"]) && is_numeric($_GET["NPage"]))
	{
		$nb_page = $_GET["NPage"];
	}
	else{
		$nb_page = 1;
	}
	$coms = GetCom($Nart,$nb_page);


?>

<div class="im"><h1><a<?php echo ' href="index.php?NArticle='.$article['ID_article'].'">'; echo $article['titre'];  ?></a></h1>
</div>
<p class="letexte"><?php echo stripslashes($article['texte']); ?><br/>
	
<p class="auteur">Cat&eacute;gorie : <a<?php echo ' href = "index.php?NPage=1&Cat='.$article['ID_categorie'].'">'.GetCategorie($article['ID_categorie']); ?></a></p>	  
<p class="auteur">Auteur : <a<?php echo ' href = "mailto:'.GetEmail($article['ID_auteur']).'">'.GetAuteur($article['ID_auteur']); ?></a></p>
<p class="auteur">Date : <?php echo $article['date']; ?></p>
<p class="auteur"><?php echo $nbcom; ?> Commentaire<?php if ($nbcom > 1){ echo "s";} ?>

<p>Commenter :</p>
<form method="post" action="<?php echo 'index.php?NArticle='.$Nart; ?>">
        <p>
            Pseudo :<br /><input name="nom" /><br />
            Mail :<br /><input name="mail" /><br/>
           
            Message :<br />
            <textarea name="texte" rows="7" cols="42"></textarea><br />
            
        	Que font <img src="images/Answer_to_Life.png"> et <?php $i=rand(0, 30); echo $tab[$i]; $reponse = $i+42; $_SESSION['reponse']=$reponse; ?> ?<br />
			<input name="terminator-killer" type="integer" /><br />
        	
        	<input class="envoyer" name="envoyer" type="submit" value="Envoyer";/>
        </p>
</form>


<div class="coms">

<?php while ($com = mysql_fetch_assoc($coms)){?>
<p class="com">
	<hr/>
	<p class="nom"><?php echo $com['nom']; ?> dit :</p>
	<?php echo stripslashes($com['texte']); ?>
	<p class="auteur">Post&eacute; le : <?php echo $com['date']; ?></p>
	
<p>
<?php }?>
</div>

<?php if($nbcom > 10){?>
	<div class="Numerotation_pages">
		<p>
			<?php $i=1;
			do {?>
				<?php 
				if($i == $nb_page) 
					{
						echo $i;
					} 
					else 
					{
						echo '<a href="index.php?NArticle='.$Nart.'&NPage='.$i.'"';
					?>
				
					 ><?php echo " ".$i." ".'</a>'; 
					 }
					 ?>
			<?php $i+=1;
			} while ($i <= ceil($nbcom/10)); ?>
		</p>
	</div>
<?php } ?>
